package fr.gdi.android.news;

import android.text.TextUtils;

public class FeedDescription implements Comparable<FeedDescription>
{
    public String name;
    public String url;
    
    public String source;
    
    public FeedDescription(String name, String url)
    {
        this.name = name;
        this.url = url;
    }
    
    @Override
    public String toString()
    {
        return name;
    }
    
    public String getPreferenceString()
    {
        return name.replaceAll(":",  " ").replace(", ", " ") + ":" + url;
    }
    
    @Override
    public boolean equals(Object o)
    {
        if (!(o instanceof FeedDescription)) return false;
        return TextUtils.equals(name, ((FeedDescription) o).name);
    }
    
    @Override
    public int hashCode()
    {
        return name.hashCode();
    }
    
    @Override
    public int compareTo(FeedDescription fd)
    {
        if (fd == null || TextUtils.isEmpty(fd.name)) return 1;
        if (TextUtils.isEmpty(name)) return -1;
        return name.compareTo(fd.name);
    }
}
